package com.lyy;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.TimeUnit;

/**
 * @author Liangyaoyun
 */
public class GuavaUtil {
        private  GuavaUtil(){

        }
        /**10分钟的缓存实例*/

        //静态内部类，什么时候使用什么时候调用
        private static final class guavaUtilHolder {
                private static final Cache<String, Object> tenMinutesCache = CacheBuilder.newBuilder()
                        .initialCapacity(10)
                        .maximumSize(100)
                        .concurrencyLevel(5)
                        .expireAfterWrite(600, TimeUnit.SECONDS)
                        .recordStats()
                        .build();
        }
//        private static Cache<String, Object> tenMinutesCache = CacheBuilder.newBuilder()
//                .initialCapacity(10)
//                .maximumSize(100)
//                .concurrencyLevel(5)
//                .expireAfterWrite(600, TimeUnit.SECONDS)
//                .recordStats()
//                .build();
        /**
         * 获取一个过期时间为10分钟的缓存实例
         *
         * @return 一个过期时间为10分钟的缓存实例
         */
        public static Cache<String, Object> getTenMinutesCache() {
            return guavaUtilHolder.tenMinutesCache;
        }
}
